<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
<ul></ul>
</body>

</html>
<script>
    function ajax(method, url, cb) {
        //1.创建xhr请求对象
        var xhr = new XMLHttpRequest()

        //2.配置请求对象
        xhr.open(method, url);

        //3.设置回调函数
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                cb(JSON.parse(xhr.responseText));
            }
        }
        //4.发送请求
        xhr.send();
    }
    ajax('get', `./ajax.json`, function (data) {
        var str = data.ajax.map((item, index) => {
            return `<li> ${item.title} </li> `
        }).join('')
        //渲染表情
        document.querySelector('ul').innerHTML = str;
    });
</script>